home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-06-24 | 1.5 KB | 91 lines | [TEXT/MPCC] |
- // OutPoint.cpp
-
-
- #include "OutPoint.h"
-
- #define TIMEOUT 2000
-
-
- OutPoint::OutPoint(
- const char *protocol,
- const char *address,
- short port)
- {
- OSStatus err = Open(protocol);
-
- if (err)
- throw err;
-
- err = Bind(port);
- if (err)
- throw err;
-
-
- char bfr [256];
- TLookupRequest req = { { 0, strlen(address), (UInt8*) address},
- { 0, 0, 0}, 1, 4000 };
- TLookupReply rep = { { 256, 0, (UInt8*) bfr }, 1 };
-
- // TLookupReply rep = { { sizeof(InetAddress), 0, (UInt8*) &fHisAddress }, 1 };
-
- MapperRef inet = OTOpenMapper(OTCreateConfiguration("dnr"), 0, &err);
- if (err)
- throw err;
- err = OTLookupName(inet, &req, &rep);
- if (err)
- throw err;
-
-
- fHisAddressSize = *(short*) bfr;
- ::BlockMoveData(bfr+4, &fHisAddress, fHisAddressSize);
- fHisAddress.inet.fPort = OUR_PORT;
-
-
-
- /*
- DNSAddress inAddress;
- strcpy(inAddress.fName, address);
- inAddress.fAddressType = kOTGenericName;
-
- TBind inBind = { { 0, sizeof(short)+strlen(address)-1, (UInt8*) &inAddress }, 0};
- TBind outBind = { { sizeof(InetAddress), 0, (UInt8*) &fHisAddress }, 0};
-
-
- err = OTResolveAddress(fEndpoint, &inBind, &outBind, TIMEOUT);
-
- if (err)
- throw err;
- fHisAddressSize = outBind.addr.len;
- */
- }
-
-
- OutPoint::~OutPoint()
- {
- }
-
-
- OSErr
- OutPoint::SendData(
- const void *data,
- long size)
- {
-
- OSStatus err;
-
- while (1) {
- TUnitData uData = {
- { 0, fHisAddressSize, (UInt8*) &fHisAddress },
- { 0, 0, NULL },
- { 0, (size_t) size, (UInt8*) data },
- };
-
- err = OTSndUData(fEndpoint, &uData);
- if (err != kOTLookErr)
- break;
- OTRcvUDErr(fEndpoint, nil);
- }
-
- return (OSErr) err;
- }
-